home *** CD-ROM | disk | FTP | other *** search
Wrap
property pSprite, pCenterOffset, pLimits, pLimitsOrigin, pPath, pMovePeriod, pMoveStart, pMoveEnd, pRotate, pRotateStart, pRotatePeriod, pRotateEnd, pLimitsLeft, pLimitsRight, pLimitsTop, pLimitsBottom, pSpeed, pRotationSpeed, pLoopiness, pWackiness on beginSprite me mInitialize(me) end on prepareFrame me mUpdate(me) end on mInitialize me pSprite = sprite(me.spriteNum) vMember = pSprite.member if pRotationSpeed > 0 then case vMember.type of #field, #picture: pRotationSpeed = 0 Message = substituteStrings(me, "Sprite ^0: ^1 behavior cannot rotate #field or #picture sprites. " & "Set the Rotation Speed parameter for this sprite to 0 to prevent this dialog from appearing.", ["^0": pSprite.spriteNum, "^1": "Random Movement and Rotation"]) alert(Message) end case end if vRect = pSprite.rect vHalfHeight = vRect.height / 2 vHalfWidth = vRect.width / 2 vMaxDimension = max(vHalfHeight, vHalfWidth) vFarCorner = max(mVectorLength(pSprite.loc - point(vRect.left, vRect.top)), mVectorLength(pSprite.loc - point(vRect.right, vRect.top)), mVectorLength(pSprite.loc - point(vRect.left, vRect.bottom)), mVectorLength(pSprite.loc - point(vRect.right, vRect.bottom))) vCenter = point(vHalfWidth, vHalfHeight) + point(vRect.left, vRect.top) pCenterOffset = vCenter - pSprite.loc pLimits = rect(pLimitsLeft, pLimitsTop, pLimitsRight, pLimitsBottom) pLimits = pLimits + rect(vFarCorner, vFarCorner, -vFarCorner, -vFarCorner) if (pLimits.width < vRect.width) or (pLimits.height < vRect.height) then Message = substituteStrings(me, "Sprite ^0: ^1 behavior movement limitations are too small to allow for full rotation of sprite.", ["^0": pSprite.spriteNum, "^1": "Random Movement and Rotation"]) alert(Message) end if pLimitsOrigin = point(pLimits.left, pLimits.top) mNewPath(me) mNewRotation(me) end on substituteStrings me, parentString, childStringList i = childStringList.count() repeat while i tempString = EMPTY dummyString = childStringList.getPropAt(i) replacement = childStringList[i] lengthAdjust = dummyString.char.count - 1 repeat while 1 position = offset(dummyString, parentString) if not position then parentString = tempString & parentString exit repeat next repeat end if if position <> 1 then tempString = tempString & parentString.char[1..position - 1] end if tempString = tempString & replacement delete me.char[1..position + lengthAdjust] end repeat i = i - 1 end repeat return parentString end on mUpdate me vTime = the milliSeconds mMove(me, vTime) mRotate(me, vTime) end on mMove me, vTime if pSpeed then if vTime < pMoveEnd then vElapsed = vTime - pMoveStart if vElapsed > 0 then vT1 = float(vElapsed) / pMovePeriod vT2 = vT1 * vT1 vT3 = vT2 * vT1 vNewPosition = pPath.p0 vModPoint = pPath.dc * vT1 vNewPosition = vNewPosition + vModPoint vModPoint = pPath.db * vT2 vNewPosition = vNewPosition + vModPoint vModPoint = pPath.da * vT3 vNewPosition = vNewPosition + vModPoint pSprite.loc = vNewPosition end if else pSprite.loc = pPath.p3 mNewPath(me) end if end if end on mRotate me, vTime if pRotationSpeed then if vTime < pRotateEnd then vElapsed = vTime - pRotateStart if vElapsed > 0 then vRotation = pRotate.start + (pRotate.diff * vElapsed / pRotatePeriod) pSprite.rotation = vRotation end if else pSprite.rotation = pRotate.end mNewRotation(me) end if end if end on mNewPath me if voidp(pPath) then pPath = [#p0: pSprite.loc, #p1: pSprite.loc, #p2: pSprite.loc, #p3: pSprite.loc] end if if pSpeed then vDest = point(random(pLimits.width), random(pLimits.height)) + pLimitsOrigin vP0 = pPath.p3 vVector = vDest - vP0 vVectorLen = mVectorLength(vVector) vLoopiness = vVectorLen * pLoopiness / 25 vP1 = mRestrain(vP0 + (pPath.p3 - pPath.p2), pLimits) if vLoopiness then vRandomPoint = point(mRandomSign() * random(vLoopiness), mRandomSign() * random(vLoopiness)) else vRandomPoint = point(0, 0) end if vP2 = mRestrain(vP0 + (vVector * 2 / 3) + vRandomPoint, pLimits) pPath = [#p0: vP0, #p1: vP1, #p2: vP2, #p3: vDest] setaProp(pPath, #dc, 3 * (pPath.p1 - pPath.p0)) setaProp(pPath, #db, (3 * (pPath.p2 - pPath.p1)) - pPath.dc) setaProp(pPath, #da, pPath.p3 - pPath.p0 - pPath.dc - pPath.db) vDistance = mVectorLength(pPath.p0 - pPath.p1) + mVectorLength(pPath.p1 - pPath.p2) + mVectorLength(pPath.p2 - pPath.p3) pMovePeriod = vDistance * 1000 / pSpeed pMoveStart = the milliSeconds pMoveEnd = pMoveStart + pMovePeriod end if end on mNewRotation me if voidp(pRotate) then pRotate = [#start: 0, #end: 0, #diff: 0] end if if pRotationSpeed then vRotation = pSprite.rotation if pRotate.diff < 0 then vOffset = random(pWackiness) else vOffset = -random(pWackiness) end if vTargetRotation = vRotation + vOffset pRotateStart = the milliSeconds pRotatePeriod = abs(vOffset) * 1000 / pRotationSpeed * 1000 / 360 pRotateEnd = pRotateStart + pRotatePeriod pRotate = [#start: vRotation, #end: vTargetRotation, #diff: vOffset] end if end on mVectorLength vVector vSquare = (vVector.locH * vVector.locH) + (vVector.locV * vVector.locV) return sqrt(vSquare) end on mRandomSign return (random(2) * 2) - 3 end on mRestrain vPoint, vRect vPoint.locH = max(vRect.left, min(vRect.right, vPoint.locH)) vPoint.locV = max(vRect.top, min(vRect.bottom, vPoint.locV)) return vPoint end on isOKToAttach me, aSpriteType, aSpriteNum case aSpriteType of #graphic: return getPos([#animGif, #bitmap, #field, #flash, #picture, #text, #vectorShape], sprite(aSpriteNum).member.type) <> 0 #script: return 0 end case end on getPropertyDescriptionList me if not (the currentSpriteNum) then exit end if vRect = (the stage).sourceRect vRect = offset(vRect, -vRect.left, -vRect.top) vMemberType = sprite(the currentSpriteNum).member.type case vMemberType of #text, #picture: vRotateSpeed = 0 otherwise: vRotateSpeed = 100 end case vPDList = [:] setaProp(vPDList, #pLimitsLeft, [#comment: "Limit of movement (left)", #format: #integer, #default: 0, #range: [#min: 0, #max: vRect.width]]) setaProp(vPDList, #pLimitsTop, [#comment: "Limit of movement (top)", #format: #integer, #default: 0, #range: [#min: 0, #max: vRect.height]]) setaProp(vPDList, #pLimitsRight, [#comment: "Limit of movement (right)", #format: #integer, #default: vRect.width, #range: [#min: 0, #max: vRect.width]]) setaProp(vPDList, #pLimitsBottom, [#comment: "Limit of movement (bottom)", #format: #integer, #default: vRect.height, #range: [#min: 0, #max: (the stage).rect.height]]) setaProp(vPDList, #pSpeed, [#comment: "Speed of movement", #format: #integer, #default: 100, #range: [#min: 0, #max: 1000]]) setaProp(vPDList, #pLoopiness, [#comment: "Loopiness", #format: #integer, #default: 10, #range: [#min: 0, #max: 25]]) setaProp(vPDList, #pRotationSpeed, [#comment: "Speed of rotation", #format: #integer, #default: vRotateSpeed, #range: [#min: 0, #max: 1000]]) setaProp(vPDList, #pWackiness, [#comment: "Wackiness", #format: #integer, #default: 120, #range: [#min: 0, #max: 360]]) return vPDList end